package sap.gui;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import javax.swing.DefaultListModel;
/*
 * F4Dialog.java
 *
 * Created on 12.03.2009, 17:46:00
 */



/**
 *
 * @author Enrique
 */
public class F4Dialog extends javax.swing.JFrame {
    private DefaultListModel lista;
    data.ProjectList[] list;

    /** Creates new form F4Dialog */

    public F4Dialog(String regex)
    {
         try
        {
             javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
        } catch(Exception e) {}

        this.regex = regex;
        initComponents();
        this.centerLocation();
        this.setSize(280, 280);
        this.setTitle("Hilfe");
        if(this.getList()>1)
            this.setVisible(true);
        else
            this.dispose();



    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setBackground(new java.awt.Color(0, 0, 0));
        getContentPane().setLayout(null);

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));
        jPanel1.setLayout(null);

        jList1.setBackground(new java.awt.Color(0, 0, 0));
        jList1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Project Definitions", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(255, 255, 255))); // NOI18N
        jList1.setForeground(new java.awt.Color(255, 255, 255));
        jScrollPane1.setViewportView(jList1);

        jPanel1.add(jScrollPane1);
        jScrollPane1.setBounds(40, 20, 190, 180);

        jButton1.setText("Select");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1);
        jButton1.setBounds(90, 210, 80, 30);

        getContentPane().add(jPanel1);
        jPanel1.setBounds(0, 0, 270, 260);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        CManager.getInstance().project = list[jList1.getSelectedIndex()].project_definition;
        ProjectManager.jTextField1.setText(list[jList1.getSelectedIndex()].project_definition);
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void centerLocation()
    {

    int maxHeight = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0].getDisplayMode().getHeight();
    int maxWidth = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0].getDisplayMode().getWidth();
    int midleX= maxWidth/2;
    int midleY= maxHeight/2;
    this.setLocation((midleX-(792/2)),(midleY-(560/2)));

    }

    public int getList()
    {
        lista = new DefaultListModel();
        list = sap.provider.Project.getList(regex);
        for(int i=0; i<list.length; i++)
        {
            lista.add(i, list[i].project_definition);
            System.out.println(list[i].project_definition);
        }
        jList1.setModel(lista);

        return list.length;
    }
    /**
    * @param args the command line arguments
    */

    private String project_def;
    private String regex;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JList jList1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
